package lb.io.apis.meta.v1.codes;


import lb.io.apimachinery.pkg.apis.meta.v1.Status;

public class LBStatus {

    private static final String pro = "A003";

    private Status status = null;

    public LBStatus(LetException ex) {
        // 获取异常上下文信息
        StackTraceElement element = ex.getStackTrace()[0];
        String caller = String.format("%s:%d", element.getFileName(), element.getLineNumber());

        this.status = Status.newBuilder().
                setPro(pro).
                setCode(ex.getCodez().getCode()).
                setMessage(ex.getCodez().toString()).
                setReason(ex.getReason()).
                setCaller(caller).
                build();
    }

    public static Status OK() {
        return Status.newBuilder().setPro(pro).setCode(Codez.Ok.getCode()).setMessage(Codez.Ok.toString()).build();
    }

    public Status getStatus() {
        return status;
    }
}
